package com.smt.ejb3.tutoria.client;

import javax.jms.Destination;
import javax.jms.MessageProducer;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
import javax.jms.TopicSession;
import javax.naming.InitialContext;

public class TopicSender {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			InitialContext ctx = new InitialContext();
			TopicConnectionFactory factory = (TopicConnectionFactory) ctx
					.lookup("ConnectionFactory");
			TopicConnection conn = factory.createTopicConnection();
			TopicSession session = conn.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
			Destination dest = (Destination)ctx.lookup("topic/ejb3destTopic");
			MessageProducer producer = session.createProducer(dest);
			producer.send(session.createTextMessage("hello, this is my first mdb topic message"));
			session.close();
			conn.close();
			System.out.println("Topic message sent");
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

}
